package day1107;

import org.junit.Test;

/**
 * @author Mr.ma
 * @since 2022/11/7 19:14
 **/
public class SingleTonTest {
    @Test
    public void hungryTest(){
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {SingleTonHungry singleTonHungry = SingleTonHungry.getInstance();
                System.out.println(Thread.currentThread().getName() + "singleTonHungry = " + singleTonHungry);}).start();
        }
        SingleTonHungry singleTonHungry = SingleTonHungry.getInstance();
        System.out.println(Thread.currentThread().getName() + "singleTonHungry = " + singleTonHungry);
    }
    @Test
    public void lazyTest(){
        new Thread(() -> {SingleTonLazy instance = SingleTonLazy.getInstance();
            System.out.println("instance = " + instance);}).start();
        SingleTonLazy instance = SingleTonLazy.getInstance();
        System.out.println("instance = " + instance);
    }
}
